package com.ktjy.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/4  10:58
 */
public class TimeSpanAspect {
    private static final Logger log= LoggerFactory.getLogger(TimeSpanAspect.class);

    public Object around(ProceedingJoinPoint jp) throws Throwable{
        log.info("【环绕增强-前置】记录{}方法执行的开始时间.",
                jp.getSignature().getName());
        long startTime=System.currentTimeMillis();
        try {
            Object result=jp.proceed();
            log.info("【环绕增强-后置】{}方法执行结果为{}.",
                    jp.getSignature().getName(), result);
            return result;
        }catch (Throwable e){
            log.info("【环绕增强-异常抛出】{}方法执行异常信息为{}.",
                    jp.getSignature().getName(), e.getMessage());
            throw e;
        }finally {
            long endTime=System.currentTimeMillis();
            log.info("【环绕增强-最终】记录{}方法执行的结束时间，并计算耗时为{}ms.",
                    jp.getSignature().getName(), (endTime - startTime));
        }
    }
}
